<template>
<div class="distributor-orders views-container">
    <el-dialog @close="resetDialogFormData" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogTableVisible">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">佣金数据</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content">
                    <div class="flex-row">
                        <div class="flex-col dialog-card">
                            <p>总佣金</p>
                            <p class="orders-red">{{formFormatData.formData.total_money}}</p>
                        </div>
                    </div>
                    <div class="wlm-dialog-main">
                        <div class="wlm-dialog-content">
                            <el-form ref="userForm" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
                                <el-form-item label="一级分销商" prop="name" v-if="formFormatData.formData.first_user_id!=0">
                                    <div class="flex-row" style="margin-left:40px;">
                                        <span>用户：</span>
                                        <img width="50" height="50" :src="formFormatData.formData.first_user_avatarUrl" style="margin:0 14px;">
                                        <div class="flex-col">
                                            <p style="min-width:120px;">{{formFormatData.formData.first_user_nickName}}</p>
                                            <span>id：{{formFormatData.formData.first_user_id}}</span>
                                        </div>
                                        <span style="margin-left:10px;">分销佣金：</span>
                                        <span class="orders-red">￥{{formFormatData.formData.first_money}}</span>
                                    </div>
                                </el-form-item>
                                <el-form-item label="二级分销商" prop="merchantlog" v-if="formFormatData.formData.second_user_id!=0">
                                    <div class="flex-row" style="margin-left:40px;">
                                        <span>用户：</span>
                                        <img width="50" height="50" :src="formFormatData.formData.second_user_avatarUrl" style="margin:0 14px;">
                                        <div class="flex-col">
                                            <p style="min-width:120px;">{{formFormatData.formData.second_user_nickName}}</p>
                                            <span>id：{{formFormatData.formData.second_user_id}}</span>
                                        </div>
                                        <span style="margin-left:10px;">分销佣金：</span>
                                        <span class="orders-red">￥{{formFormatData.formData.second_money}}</span>
                                    </div>
                                </el-form-item>
                                <el-form-item label="三级分销商" prop="businessbackgroundmap" v-if="formFormatData.formData.third_user_id!=0">
                                    <div class="flex-row" style="margin-left:40px;">
                                        <span>用户：</span>
                                        <img width="50" height="50" :src="formFormatData.formData.third_user_avatarUrl" style="margin:0 14px;">
                                        <div class="flex-col">
                                            <p style="min-width:120px;">{{formFormatData.formData.third_user_nickName}}</p>
                                            <span>id：{{formFormatData.formData.third_user_id}}</span>
                                        </div>
                                        <span style="margin-left:10px;">分销佣金：</span>
                                        <span class="orders-red">￥{{formFormatData.formData.third_money}}</span>
                                    </div>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" type="primary" @click="dialogTableVisible = false">确定</el-button>
        </footer>
    </el-dialog>
    <div class="wlm-table">
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="90px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="订单编号：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.order_no" placeholder="请输入订单编号" style="width:200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="会员信息：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.member" placeholder="手机号/微信昵称" style="width:200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="商品名称：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.goods" placeholder="请输入商品名称或编号" style="width:200px;"></el-input>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter">
                    <el-form-item label="结算状态：">
                        <el-select v-model="tableFormatData.userTable.files.is_settled" placeholder="请选择" style="width:200px;">
                            <!-- <el-option :label="'全部'" :value="2">
                            </el-option> -->
                            <el-option :label="'未结算'" :value="0">
                            </el-option>
                            <el-option :label="'已结算'" :value="1">
                            </el-option>
                            <el-option :label="'结算中'" :value="2">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="下单时间：">
                        <el-date-picker v-model="tableFormatData.userTable.files.time" value-format="timestamp" type="datetimerange" :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right">
                        </el-date-picker>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button :disabled="tableFormatData.userTable.tableData.length==0" plain icon="document" :data-query="JSON.stringify(tableFormatData.userTable.files)" v-exceldown="{path:'outDealerPut&',query: {}}">{{$t('excel.export') }}</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-tabs v-model="tableFormatData.userTable.files.order_type" type="card" @tab-click="filesSerch">
                <el-tab-pane label="普通订单" name="0"></el-tab-pane>
                <el-tab-pane label="会员订单" name="40"></el-tab-pane>
            </el-tabs>
            <el-table :ref="tableFormatData.userTable.key" v-loading="!isTableFormatGetEnd" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column align="left" class-name="no-column">
                    <!-- <el-table-column type="selection" width="30"  class-name="no-bor">
                    </el-table-column> -->
                    <el-table-column width="30" class-name="no-bor">
                    </el-table-column>
                    <el-table-column :label="tableFormatData.userTable.files.order_type=='0'?'商品信息':'会员卡名称'" align="left" class-name="no-bor">
                        <template slot-scope="scope">
                            <div class="flex-row mar-b-20 goods-list">
                                <img v-if="scope.row.image" width="50" height="50" :src="scope.row.image.file_path" style="margin-right:10px;">
                                <el-popover class="scale-grow" placement="top-start" width="200" trigger="hover" :content="scope.row.goods_name">
                                    <p slot="reference" class="ellips_line2">{{ scope.row.goods_name }}</p>
                                </el-popover>
                            </div>
                            <div class="flex-row mar-b-20" style="background:rgb(235, 238, 245);position: absolute;top: 0;left: -30px;right: -9999px;padding: 12px;">
                                <span class="no-nowrap scale-grow">订单编号:{{scope.row.order_no}}</span>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="单价/数量"  class-name="no-bor">
                        <template slot-scope="scope">
                            <div class="flex-col goods-list">
                                <p><span class="orders-red">￥</span>{{scope.row.pay_price}}</p>
                                <p>{{scope.row.total_num || 0}}件</p>
                            </div>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column prop="date" label="用户" >
                    <template slot-scope="scope">
                        <p class="pad-t-50">
                            <router-link tag="span" :to="{path:'/user/managementUserEdit', query:{user_id:scope.row.user_id}}">
                                <el-button type="text">{{scope.row.nickName}}</el-button>
                            </router-link>
                        </p>
                        <p>{{scope.row.realname}}</p>
                        <p>{{scope.row.mobile}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="实付款/订单来源" >
                    <template slot-scope="scope">
                        <p class="pad-t-50"><span class="orders-red">￥</span>{{scope.row.pay_price}}</p>
                        <p v-if="scope.row.express_type=='1'"><span class="orders-gray font-12">运费{{scope.row.express_price}}元</span></p>
                        <p>{{sourceType[`${scope.row.source}`]}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="下单时间" >
                    <template slot-scope="scope">
                        <p class="pad-t-50">{{scope.row.create_time}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="订单状态" >
                    <template slot-scope="scope">
                        <div class="flex-col flex-justify-c pad-t-50">
                            <p v-if="scope.row.order_status==10">进行中</p>
                            <p v-if="scope.row.order_status==20">取消</p>
                            <p v-if="scope.row.order_status==21">待取消</p>
                            <p v-if="scope.row.order_status==30">已完成</p>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="结算状态/总佣金" >
                    <template slot-scope="scope">
                        <div class="flex-col flex-justify-c pad-t-50">
                            <span>{{scope.row.is_settled==0?"未结算":scope.row.is_settled==1?"已结算":'结算中'}}</span>
                            <span class="orders-red">￥{{scope.row.total_money}}</span>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" prop="address" label="操作" >
                    <template slot-scope="scope">
                        <div class="flex-col pad-t-50">
                            <div style="position: absolute;right: 15px;top:5px;" v-if="tableFormatData.userTable.files.order_type=='0'">
                                <router-link class="wlm-text" tag="span" :to="{path:`${linkDetailType[`${scope.row.express_type}`]}`, query:{order_id:scope.row.order_id,nickName:scope.row.nickName,user_id:scope.row.user_id}}">
                                    <el-button type="text">查看订单</el-button>
                                </router-link>
                            </div>
                            <div class="operation-group">
                                <el-button class="wlm-text" type="text" @click="formFormatDialogEditEvt({id:scope.row.id,toggle:'dialogTableVisible'})">佣金数据</el-button>
                                <!-- <div class="btn-line"></div>
                                <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.id)">删除</el-button> -->
                            </div>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <!-- <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox> -->
                    <!-- <el-button class="right-8" :disabled="isGroup" type="primary" size="mini">批量退款</el-button> -->
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  getDistributorOrder,
  delDistributorOrder,
  getDistributorCommission
} from '@/api/distribution'
import mixins from '@/mixins/mixins'
import exceldown from '@/directive/exceldown'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'DistributorOrders',
  components: {

  },
  directives: {
    exceldown
  },
  computed: {

  },
  data() {
    return {
      sourceType: {
        '1': '导入',
        '2': '微信小程序',
        '3': 'H5',
        '4': '公众号',
        '5': '安卓',
        '6': '苹果',
        '7': '支付宝小程序',
        '8': '百度小程序',
        '9': '头条小程序',
        '-': '-'
      },
      linkDetailType: {
        '4': 'ordersCardPasswordManagementDetail',
        '3': '/orders/ordersVerificationManagementDetail',
        '2': '/orders/ordersComeStoreManagementDetail',
        '1': '/orders/ordersExpressManagementDetail'
      },
      dialogTableVisible: false,
      value: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getDistributorOrder,
            delList: delDistributorOrder
          },
          tableData: [],
          files: {
            order_no: '',
            member: '',
            goods: '',
            is_settled: '',
            order_type: '0',
            time: [],
            ids: [],
            checkall: '0',
            Recycle: '0'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      },
      formFormatData: {
        key: 'userForm',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: getDistributorCommission,
            params: {
              id: ''
            }
          },
          submitForm: getDistributorCommission
        },
        formData: {
          id: '',
          total_money: '',
          first_money: '',
          second_money: '',
          third_money: '',
          first_user_nickName: '',
          first_user_avatarUrl: '',
          second_user_nickName: '',
          second_user_avatarUrl: '',
          third_user_nickName: '',
          third_user_avatarUrl: '',
          first_user_id: '',
          second_user_id: '',
          third_user_id: ''
        },
        rules: {}
      }
    }
  },
  methods: {
  }
}
</script>

<style lang="scss" scoped>
.distributor-orders {
    /deep/ .is-left.no-column .cell {
        display: none !important;
    }

    .logo {
        height: 32px;
        width: 32px;
        border-radius: 32px;
        vertical-align: middle;
    }

    .pad-t-50 {
        padding-top: 48px;
    }

    /deep/ .el-table__body tr:hover>td {
        background-color: transparent !important;
    }

    .goods-list:nth-of-type(1) {
        padding-top: 48px;
    }

    & .orders-red {
        color: rgb(245, 108, 108);
    }

    /deep/ .no-bor {
        border-right: none;
    }

    .dialog-card {
        margin-left: 40px;
        padding: 10px 36px;
        margin-bottom: 20px;
        font-size: 16px;
        line-height: 1.7;
        background: #f2f2f2;
        border-radius: 6px;
        width: auto;
        border: 1px solid #dddddd;
    }

    .opacity-0 {
        opacity: 0;
    }
}
</style>
